package com.gaoxin.api.service.stuservice;

import java.util.List;
import java.util.logging.Logger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gaoxin.api.dao.studao.StuInfoDao;
import com.gaoxin.api.entity.ConfigEntity;
import com.gaoxin.api.entity.stuentity.DormInfoEntity;
import com.gaoxin.api.entity.stuentity.FamilyInfoEntity;
import com.gaoxin.api.entity.stuentity.SchoolInfoEntity;
import com.gaoxin.api.entity.stuentity.StuInfoEntity;

/**
 * 学生系统接口-业务层
 *
 * @author fanyue
 * @email 859485490@qq.com
 * @date 2018-07-12 15:21
 */
@Service
public class StuInfoService {
	Logger log = Logger.getLogger("~~StuInfoService~~~~~~~~");
	@Autowired
	private StuInfoDao stuInfoDao;
	@Autowired
	private ConfigEntity configEntity;

	/**
	 * 查询学生基本信息
	 * 
	 * @param stuNumber
	 * @return StuInfoEntity
	 * @throws Exception
	 */
	public StuInfoEntity queryStuInfo(String stuNumber) throws Exception {
		StuInfoEntity entity = new StuInfoEntity();
		log.info("查询学生信息开始。。。" + stuNumber);
		try {
//			System.out.println("++++++++++++++"+configEntity.getBaseDirPath());
			entity = stuInfoDao.queryStuInfo(stuNumber);
			String headImage = entity.getHeadImage();
			if (!headImage.substring(0, 4).equals("http")) {
				headImage = configEntity.getBaseDirPath() + entity.getHeadImage();
				entity.setHeadImage(headImage);
			}
			// System.out.println("学生基本信息***********" + entity.toString());
		} catch (Exception e) {
			log.warning("查询学生信息异常。。。");
			e.printStackTrace();
		}
		return entity;
	}
	
	/**
	 * 查询学生学籍信息
	 * 
	 * @param stuNumber
	 * @return SchoolInfoEntity
	 * @throws Exception
	 */
	public SchoolInfoEntity querySchoolInfo(String stuCode) throws Exception {
		SchoolInfoEntity entity = new SchoolInfoEntity();
		log.info("查询学生学籍信息开始。。。" + stuCode);
		try {
			entity = stuInfoDao.querySchoolInfo(stuCode);
			String status = "";
			if(entity.getStatus().equals("1")) status = "在校";
			if(entity.getStatus().equals("2")) status = "休学";
			if(entity.getStatus().equals("3")) status = "退学";
			if(entity.getStatus().equals("4")) status = "毕业";
			if(entity.getStatus().equals("5")) status = "开除";
			if(entity.getStatus().equals("6")) status = "入伍";
			if(entity.getStatus().equals("7")) status = "毕业实习";
			if(entity.getStatus().equals("8")) status = "保留学籍";
			entity.setStatus(status);
			// System.out.println("查询学生学籍信息***********" + entity.toString());
		} catch (Exception e) {
			log.warning("查询学生学籍信息异常。。。");
			e.printStackTrace();
		}
		return entity;
	}
	
	/**
	 * 查询学生宿舍信息
	 * 
	 * @param stuNumber
	 * @return DormInfoEntity
	 * @throws Exception
	 */
	public DormInfoEntity queryDromInfo(String stuCode) throws Exception {
		DormInfoEntity entity = new DormInfoEntity();
		log.info("查询学生宿舍信息开始。。。" + stuCode);
		try {
			entity = stuInfoDao.queryDromInfo(stuCode);
			// System.out.println("查询学生宿舍信息***********" + entity.toString());
		} catch (Exception e) {
			log.warning("查询学生宿舍信息异常。。。");
			e.printStackTrace();
		}
		return entity;
	}
	
	/**
	 * 查询学生家庭信息
	 * 
	 * @param stuNumber
	 * @return FamilyInfoEntity
	 * @throws Exception
	 */
	public FamilyInfoEntity queryFamilyInfo(String stuCode) throws Exception {
		FamilyInfoEntity entity = new FamilyInfoEntity();
		log.info("查询学生家庭信息开始。。。" + stuCode);
		try {
			entity = stuInfoDao.queryFamilyInfo(stuCode);
			String relation = "";
			if (entity != null) {
				if(entity.getRelation().equals("1")) relation = "父";
				if(entity.getRelation().equals("2")) relation = "母";
				if(entity.getRelation().equals("3")) relation = "其他";
				entity.setRelation(relation);
			}
			// System.out.println("查询学生家庭信息***********" + entity.toString());
		} catch (Exception e) {
			log.warning("查询学生家庭信息异常。。。");
			e.printStackTrace();
		}
		return entity;
	}
	/**
	 *根据院系专业查询学生
	 * @return
	 */
	public List<StuInfoEntity> queryStuByMajorId(StuInfoEntity stuInfoEntity)throws Exception{
		stuInfoEntity.setHeadImage(configEntity.getBaseDirPath());
		return stuInfoDao.queryStuByMajorId(stuInfoEntity);
	}
	
	/**
	 *根据院系专业查询学生
	 * @return
	 */
	public List<StuInfoEntity> queryStuAllinfo(StuInfoEntity stuInfoEntity)throws Exception{
		stuInfoEntity.setHeadImage(configEntity.getBaseDirPath());
		return stuInfoDao.queryStuAllinfo(stuInfoEntity);
	}
}
